<template>
    <mescroll-uni
        ref="mescrollRef"
        @init="mescrollInit"
        :height="height"
        :down="downOption"
        @down="downRefresh"
        :up="upOption"
        @up="getData">
        <view class="wrapper">
            <pending-list-item
                v-for="(item, index) in datas"
                @grabOrder="grabOrder"
                :item="item"
                :index="index"
                :key="index"></pending-list-item>
        </view>
    </mescroll-uni>
</template>

<script>
import { mapGetters } from "vuex"
import pendingListItem from "@/pages_tms/components/order/pending-list-item.vue"
import { GetGuideStorePage } from "@/service/api/store.js"
import { MapSendPage, SetMapSendDelivery } from "@/pages_tms/service/logistics.js"
import storage from "@/uni-sub-base/utils/storage.js"
export default {
    components: {
        pendingListItem,
    },
    props: {
        height: {
            type: String,
            default: "300px",
        },
        type: {
            type: Number,
            default: 1,
        },
        selectType: {
            type: String,
            default: "",
        },
    },
    data() {
        return {
            datas: [],
            allLength: 0,
            data: [],
            productList: [],
            downOption: {
                use: true,
            },
            isLoaded: false,
            param: {
                // businessId:1
            },
        }
    },
    computed: {
        ...mapGetters(["getUpMapView"]),
    },
    watch: {
        //监听更新
        getUpMapView(e) {
            console.log("aaaa")
            this.downRefresh()
        },
    },
    mounted() {
        this.refresh()
    },
    methods: {
        //获取列表数据
        getData(page) {
            let param = this.param
            param.pageSize = page.size
            param.pageIndex = page.num
            param.typeId = storage.getCache("typeId")
            MapSendPage(param).then((res) => {
                if (res.State == 1) {
                    this.mescroll.endBySize(res.Data.length, res.RecordAmout)
                    this.datas = this.datas.concat(res.Data)
                    this.allLength = res.RecordAmout
                    this.isLoaded = true
                } else {
                    this.mescroll.endBySize(0, 0)
                    this.easyToast(res.Msg)
                }
            })
        },
        //刷新
        refresh(param = null) {
            if (param) {
                this.param = param
            }
            this.downRefresh()
        },
        //刷新
        downRefresh() {
            console.log("nnnn")
            this.datas = []
            this.mescroll.resetUpScroll()
        },
        grabOrder(id) {
            let path = {
                mapSendId: id,
            }
            SetMapSendDelivery(path).then((res) => {
                if (res.State == 1) {
                    this.easyToast("抢单成功！")
                    setTimeout((e) => {
                        this.downRefresh()
                    }, 1500)
                } else {
                    this.easyToast(res.Msg)
                }
            })
        },
    },
}
</script>

<style lang="scss">
.wrapper {
    padding: $app-page-padding;
}
</style>
